package com.heo.demo.springdemo.controller;

import com.heo.demo.springdemo.dao.UserDao;
import com.heo.demo.springdemo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 刘康
 * @Date 2022-11-20 16:19
 * @Desc
 **/
@RestController
public class UserController {

    @Autowired
    private UserDao userDao;

    @GetMapping(path = "/user")
    public List<User> findAllUser() {
        List<User> all = userDao.findAll();
        return all;
    }

    @PostMapping(path = "/user")
    public User createUser() {
        // 创建用户
        User user = new User();
        user.setUsername("liukang");
        user.setPassword("password");
        user.setName("刘康");
        user.setAge(15);

        userDao.save(user);
        return user;
    }

}
